package com.s.core.root.strategy.factor.point;

import com.s.core.root.data._AllData;
import com.s.core.root.data._PicN;
import com.s.core.root.data._PointN;
import com.s.core.root.strategy.base.Factor;
import com.s.core.root.strategy.base.Feature;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.function.Function;

/**
 * Point特征：描述足够强(最后一个Point和非最后一个Point认定足够强的程度不同)
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class F_Point_Strong implements Factor, Feature {
    //400/5252
    public static final Function<Integer, Integer> LAST_POS_N_LIMIT = total ->
            new BigDecimal(total).multiply(new BigDecimal("0.0761")).
                    setScale(0, RoundingMode.UP).intValue();
    //200/5252
    public static final Function<Integer, Integer> SKIP_POS_N_LIMIT = total ->
            new BigDecimal(total).multiply(new BigDecimal("0.0380")).
                    setScale(0, RoundingMode.UP).intValue();

    private int pos;

    @Override
    public void process(_AllData allData) {
        for (_PicN picN : allData.picNMap.values()) {
            process(picN.getPointNList1());
            process(picN.getPointNList2());
        }
    }

    private void process(List<_PointN> pointNList) {
        for (_PointN pointN : pointNList) {
            if (pointN.isTp()) {
                continue;
            }
            Function<Integer, Integer> nLimitFunction = pointN.containFeature(F_Point_Last.class) ?
                    LAST_POS_N_LIMIT : SKIP_POS_N_LIMIT;
            if (pointN.pos() <= nLimitFunction.apply(pointN.total)) {
                pointN.addFeature(new F_Point_Strong(pointN.pos()));
            }
        }
    }
}
